# -*- coding: iso-8859-1 -*-

from elementtree import ElementTree

SAMPLE_XML = ElementTree.XML("""
<body>
  <tag0>text</tag0>
  <section>
    <tag1>subtext</tag1>
  </section>
  <section>
    <tag1>subtext</tag1>
  </section>
  <section>
    <tag1>subtext</tag1>
  </section>
</body>
""")

def summarize(elem):
    return elem.tag

def summarize_list(seq):
    return map(summarize, seq)

def find():
    """
    Test find methods (including xpath syntax).

    >>> elem = SAMPLE_XML
    >>> elem.find("tag").tag
    'tag'
    >>> ElementTree.ElementTree(elem).find("tag").tag
    'tag'
    >>> elem.find("section/tag").tag
    'tag'
    >>> ElementTree.ElementTree(elem).find("section/tag").tag
    'tag'
    >>> elem.findtext("tag")
    'text'
    >>> elem.findtext("tog")
    >>> elem.findtext("tog", "default")
    'default'
    >>> ElementTree.ElementTree(elem).findtext("tag")
    'text'
    >>> elem.findtext("section/tag")
    'subtext'
    >>> ElementTree.ElementTree(elem).findtext("section/tag")
    'subtext'
    >>> summarize_list(elem.findall("tag"))
    ['tag', 'tag']
    >>> summarize_list(elem.findall("*"))
    ['tag', 'tag', 'section']
    >>> summarize_list(elem.findall(".//tag"))
    ['tag', 'tag', 'tag']
    >>> summarize_list(elem.findall("section/tag"))
    ['tag']
    >>> summarize_list(elem.findall("section//tag"))
    ['tag']
    >>> summarize_list(elem.findall("section/*"))
    ['tag']
    >>> summarize_list(elem.findall("section//*"))
    ['tag']
    >>> summarize_list(elem.findall("section/.//*"))
    ['tag']
    >>> summarize_list(elem.findall("*/*"))
    ['tag']
    >>> summarize_list(elem.findall("*//*"))
    ['tag']
    >>> summarize_list(elem.findall("*/tag"))
    ['tag']
    >>> summarize_list(elem.findall("*/./tag"))
    ['tag']
    >>> summarize_list(elem.findall("./tag"))
    ['tag', 'tag']
    >>> summarize_list(elem.findall(".//tag"))
    ['tag', 'tag', 'tag']
    >>> summarize_list(elem.findall("././tag"))
    ['tag', 'tag']
    >>> summarize_list(ElementTree.ElementTree(elem).findall("/tag"))
    ['tag', 'tag']
    >>> summarize_list(ElementTree.ElementTree(elem).findall("./tag"))
    ['tag', 'tag']
    """

"""
<body>
  <tag0>text</tag0>
  <section>
    <tag1>subtext</tag1>
  </section>
  <section>
    <tag1>subtext</tag1>
  </section>
  <section>
    <tag1>subtext</tag1>
  </section>
</body>
"""

if __name__ == "__main__":
    ''' '''
    #import doctest
    #doctest.testmod()

    elem = SAMPLE_XML
    #print elem.findtext("section/tag1")

    for n in elem.findall("section/tag1"):
        print n.text


















